﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ICeFramework.Business.DataLayer
{
    public class EntityObjectCollection : ICollection<IEntityObject>
    {
        private List<IEntityObject> _list = new List<IEntityObject>();

        public IEntityObject this[int columnIndex]
        {
            get 
            {
                if (columnIndex >= _list.Count)
                {
                    return null;
                }
                return _list[columnIndex]; 
            }
        }

        public IEntityObject this[string columnName]
        {
            get 
            {
                foreach (IEntityObject item in _list)
                {
                    if (item.Column.Name == columnName)
                    {
                        return item;
                    }
                }
                return null; 
            }
        }

        #region ICollection<IEntityObject> Members

        public void Add(IEntityObject item)
        {
            _list.Add(item);
        }

        public void Clear()
        {
            _list.Clear();
        }

        public bool Contains(IEntityObject item)
        {
            return _list.Contains(item);
        }

        public void CopyTo(IEntityObject[] array, int arrayIndex)
        {
            _list.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return _list.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(IEntityObject item)
        {
            return _list.Remove(item);
        }

        #endregion

        #region IEnumerable<IEntityObject> Members

        public IEnumerator<IEntityObject> GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        #endregion
    }
}
